// 接口的调用进行封装
/**
 * 1. http://www.baodi.com/api/login
 *    http://www.baodi.com/api/list
 *    http://www.baodi.com/api/delete?id = 1
 */

import type { AxiosResponse } from 'axios';
import xiosInstance from './axios';
import type { User } from '../types/user';

// 请求参数类型
type ListType = {
    username: string,
    password: string
}
// 响应数据类型
type BackType = {
    token: string,
    text: string,
}

export function Login (userInfo: User) {
    return xiosInstance.post<User, AxiosResponse<BackType, User>>('/api/auth/login', userInfo);
}

const data = Login({username:'111', password:'222'});
data.then(data => {
    const apidata = data.data;
    console.log(apidata.text);
})

export function getList() {
    return xiosInstance.get<ListType[], AxiosResponse<ListType[]>>('http://www.baodi.com/api/list');
}

// 缓存, 状态 + react + query